package jdk21.generics;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @description: 泛型
 * @author: grf
 * @date: 2024/8/22
 */
public class Generics {

    public static void main(String[] args) {
        // System.out.println(convertToList(new String[]{"a", "b", "c"}));
        // System.out.println(convertToList(new Integer[]{1, 2, 3}));
        processNumbers(Arrays.asList(1.2, 2.1, 3.1));

        List<String> list = Collections.emptyList();
        List<String> list1 = new ArrayList<>();
    }

    /**
     * @description: 类型转换
     * @author: grf
     * @date: 2024/8/22
     */
    public static <T> List<T> convertToList(T[] arrays) {
        return Arrays.asList(arrays);
    }
    /**
     * @description: 泛型通配符
     * @author: grf
     * @date: 2024/8/22
     */
    public static <T extends Number> void processNumbers(List<? extends T> numbers) {
        numbers.forEach(System.out::println);
    }

    public static <T extends Comparable<T>> T findMax(List<T> list) {
        return Collections.max(list);
    }
}
